/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ejb.persistence;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Julien
 */
@Entity
@Table(name="AUTHOR")
@NamedQuery(name="Author.getAllAuthors", query="SELECT a FROM Author a")
public class Author implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="Id_Author")
    private Long id;

    @Column(name="Author_First_Name")
    private String firstName;
    
    @Column(name="Author_Last_Name")
    private String lastName;
    
    @JoinTable(
            name="Written_By",
            inverseJoinColumns={@JoinColumn(name="Id_Book")},
            joinColumns={@JoinColumn(name="Id_Author")})
    @ManyToMany
    private List<Book> books;
    
/* -----------------------------------------------------------------------------
 * ---------------------------GETTERS AND SETTERS-------------------------------
 * ---------------------------------------------------------------------------*/    
    public Long getId() {
        return id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public List<Book> getBooks() {
        return books;
    }

    public void setBooks(List<Book> books) {
        this.books = books;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Author)) {
            return false;
        }
        Author other = (Author) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ejb.persistence.Author[ id=" + id + " ]";
    }
    
}
